﻿using System;
using System.Globalization;
using Avalonia.Data.Converters;
using FileManager.Lib.FileModels;
using LuckyFish.FileManager.Models;
using Material.Icons;

namespace LuckyFish.FileManager.Converters;

public class IconConverter : IValueConverter
{
    public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
    {
        if (value is string s)
            return Enum.Parse<MaterialIconKind>(s);

        if (value is IFileSystem)
        {
            if (value is DriveOperation)
            {
                return MaterialIconKind.ContentSave;
            }

            if (value is DirectoryOperation)
            {
                return MaterialIconKind.Folder;
            }

            if (value is FileOperation file)
            {
                return file.Extension switch
                {
                    ".cs" => MaterialIconKind.LanguageCsharp,
                    ".css" => MaterialIconKind.LanguageCss3,
                    ".c" => MaterialIconKind.LanguageC,
                    ".cpp" => MaterialIconKind.LanguageCpp,
                    ".java" => MaterialIconKind.LanguageJava,
                    ".js" => MaterialIconKind.LanguageJavascript,
                    ".html" => MaterialIconKind.LanguageHtml5,
                    ".xaml" or "axaml" or ".xml" => MaterialIconKind.LanguageXaml,
                    ".swift" => MaterialIconKind.LanguageSwift,
                    ".md" => MaterialIconKind.LanguageMarkdown,
                    ".ttf" => MaterialIconKind.Language,
                    _ => MaterialIconKind.File
                };
            }
        }

        if (value is DriveSimpleOperation)
        {
            return MaterialIconKind.ContentSave;
        }

        if (value is CommonModel common)
        {
            switch (common.Name)
            {
                case "Desktop":
                    return MaterialIconKind.DesktopWindows;
                case "Music":
                    return MaterialIconKind.Music;
                case "Videos":
                    return MaterialIconKind.Video;
                case "Documents":
                    return MaterialIconKind.FileDocument;
                case "Pictures":
                    return MaterialIconKind.Picture360;
            }
        }
        
        return value;
    }

    public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
    {
        return value;
    }
}